// pages/hackson_group_detail/hackson_group_detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    group: "",
    marathon: "",
    members: [],
    captain: "",
    detail: "",
    supplement: 0,
    url: "",
    photo: [],
    students: "",
    status:""
  },

  supplement: function () {
    var that = this

    var group = that.data.group
    var marathon = that.data.marathon
    var status = that.data.status

    wx.navigateTo({
      url: '../hackson_group_supplyment/hackson_group_supplyment?group=' + group + "&marathon=" + marathon + "&status=" + status
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this

    that.setData({
      students: options.students,
      group: options.group,
      marathon: options.marathon,
      status: options.status
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this

    var kind = getApp().globalData.kind
    var studentNo = getApp().globalData.user.studentNo
    var students = that.data.students
    console.log(studentNo, students, students.split(","))

    if (kind == "1" && students.split(",").includes(studentNo)) {
      that.setData({
        supplement: 1
      })
    }

    //获得项目详情
    wx.request({
      url: getApp().globalData.my_server + "/hackson/get_details_by_marathon_id_and_group_name",
      data: {
        marathon_id: that.data.marathon,
        name: that.data.group
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        console.log(res)
        if (res.data.error_no == 2) {
          wx.showModal({
            title: '哎呀～',
            content: res.data.error_msg,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else if (res.data.error_no == 0) {

          var photo = res.data.group.photo
          if (photo == "" || photo == undefined) {
            photo = []
          } else {
            photo = photo.split(",")
          }

          that.setData({
            group: that.data.group,
            marathon: that.data.marathon,
            members: res.data.group.members,
            captain: res.data.group.captain,
            detail: res.data.group.detail,
            url: res.data.group.url,
            photo: photo
          })
        }
      },
      fail: function (res) {
        wx.showModal({
          title: '哎呀～',
          content: '获得项目详情失败',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定')
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
        console.log("fail!", res)
      },
      complete: function (res) {

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})